﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:lml="http://www.mondeil.fr"
                exclude-result-prefixes="msxsl xsi xsd lml"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/lml:SchemaFieldsDiff">
    <Schema>
      <FieldsToGet>
        
        <!--Champs à récupérer car les valeurs sont manquantes ou différentes dans les SPFields - On exclue les parties prises en charge par le type de contenu -->
        <xsl:apply-templates select="//lml:FieldDiffInfo[@xsi:type!='SourceAttributeMissing' and @Name!='DisplayName' and @Name!='Name' and @Name!='ReadOnly' and @Name!='ShowInNewForm' and @Name!='ShowInEditForm' and @Name!='ShowInDisplayForm']/../.."/>

      </FieldsToGet>
      <FieldsToRename>
        <xsl:apply-templates select="//lml:FieldDiffInfo[@xsi:type='AttributeValueDiff' and @Name='Name']" mode="rename"/>
      </FieldsToRename>
    </Schema>
  </xsl:template>

  <xsl:template match="lml:FieldDiffs">
    <xsl:element name="FieldRef">
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="lml:Diffs/lml:FieldDiffInfo[@xsi:type='AttributeValueDiff' and @Name!='Name']" mode="attrDiff"/>
      <xsl:apply-templates select="lml:Diffs/lml:FieldDiffInfo[@xsi:type='AttributeMissing' and @Name!='EnforceUniqueValues']" mode="attrMissing"/>
      <xsl:apply-templates select="lml:Diffs/lml:FieldDiffInfo[@xsi:type='FormulaValueDiff']" mode="formulaDiff"/>
      <xsl:apply-templates select="lml:Diffs/lml:FieldDiffInfo[@xsi:type='Formula']" mode="formulaf"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="lml:FieldDiffInfo" mode="attrDiff">
    <xsl:element name="Remplacer">
      <xsl:attribute name="Name">
        <xsl:value-of select="@Name"/>
      </xsl:attribute>
      <xsl:attribute name="Value">
        <xsl:value-of select="lml:Source/text()"/>
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

  <xsl:template match="lml:FieldDiffInfo" mode="attrMissing">
    <xsl:element name="Ajouter">
      <xsl:attribute name="Name">
        <xsl:value-of select="@Name"/>
      </xsl:attribute>
      <xsl:attribute name="Value">
        <xsl:value-of select="@Value"/>
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

  <xsl:template match="lml:FieldDiffInfo" mode="formulaDiff">
    <xsl:element name="CopierChamp">
      <xsl:attribute name="Name">
        <xsl:value-of select="@Name"/>
      </xsl:attribute>
      <xsl:attribute name="Value">
        <xsl:value-of select="lml:Source/text()"/>
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

  <xsl:template match="lml:FieldDiffInfo" mode="formula">
    <xsl:element name="CopierChamp">
      <xsl:attribute name="Name">
        <xsl:value-of select="@Name"/>
      </xsl:attribute>
      <xsl:attribute name="Value">
        <xsl:value-of select="@Value"/>
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

  <xsl:template match="lml:FieldDiffInfo" mode="rename">
    <xsl:element name="Renommer">
      <xsl:attribute name="ID">
        <xsl:value-of select="../../@ID"/>
      </xsl:attribute>
      <xsl:attribute name="Source">
        <xsl:value-of select="lml:Source/text()"/>
      </xsl:attribute>
      <xsl:attribute name="Par">
        <xsl:value-of select="lml:Comparison/text()"/>
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

  <xsl:template match="@* | node()" mode="copy">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" mode="copy"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="text()"/>

</xsl:stylesheet>
